{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b6a193ea-b95c-4c9a-bf17-5176ff6729d0",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2a06bcb2-072e-4160-9dec-06e2ad94e82f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p_val</th>\n",
       "      <th>avg_log2FC</th>\n",
       "      <th>pct.1</th>\n",
       "      <th>pct.2</th>\n",
       "      <th>p_val_adj</th>\n",
       "      <th>cluster</th>\n",
       "      <th>gene</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.273332e-143</td>\n",
       "      <td>0.738706</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.991</td>\n",
       "      <td>1.746248e-139</td>\n",
       "      <td>0</td>\n",
       "      <td>RPS12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6.817653e-143</td>\n",
       "      <td>0.693452</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.995</td>\n",
       "      <td>9.349729e-139</td>\n",
       "      <td>0</td>\n",
       "      <td>RPS6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.661810e-141</td>\n",
       "      <td>0.737260</td>\n",
       "      <td>0.999</td>\n",
       "      <td>0.992</td>\n",
       "      <td>6.393206e-137</td>\n",
       "      <td>0</td>\n",
       "      <td>RPS27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8.158412e-138</td>\n",
       "      <td>0.626608</td>\n",
       "      <td>0.999</td>\n",
       "      <td>0.995</td>\n",
       "      <td>1.118845e-133</td>\n",
       "      <td>0</td>\n",
       "      <td>RPL32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.177478e-130</td>\n",
       "      <td>0.633696</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.994</td>\n",
       "      <td>7.100394e-126</td>\n",
       "      <td>0</td>\n",
       "      <td>RPS14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11624</th>\n",
       "      <td>9.164182e-03</td>\n",
       "      <td>4.822627</td>\n",
       "      <td>0.077</td>\n",
       "      <td>0.009</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>8</td>\n",
       "      <td>CDK2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11625</th>\n",
       "      <td>9.201825e-03</td>\n",
       "      <td>2.670857</td>\n",
       "      <td>0.154</td>\n",
       "      <td>0.030</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>8</td>\n",
       "      <td>BCL2L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11626</th>\n",
       "      <td>9.334658e-03</td>\n",
       "      <td>2.912823</td>\n",
       "      <td>0.154</td>\n",
       "      <td>0.030</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>8</td>\n",
       "      <td>ETV6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11627</th>\n",
       "      <td>9.838577e-03</td>\n",
       "      <td>3.310543</td>\n",
       "      <td>0.077</td>\n",
       "      <td>0.009</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>8</td>\n",
       "      <td>VWA8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11628</th>\n",
       "      <td>9.946527e-03</td>\n",
       "      <td>2.067077</td>\n",
       "      <td>0.538</td>\n",
       "      <td>0.309</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>8</td>\n",
       "      <td>AP2M1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>11629 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               p_val  avg_log2FC  pct.1  pct.2      p_val_adj  cluster    gene\n",
       "0      1.273332e-143    0.738706  1.000  0.991  1.746248e-139        0   RPS12\n",
       "1      6.817653e-143    0.693452  1.000  0.995  9.349729e-139        0    RPS6\n",
       "2      4.661810e-141    0.737260  0.999  0.992  6.393206e-137        0   RPS27\n",
       "3      8.158412e-138    0.626608  0.999  0.995  1.118845e-133        0   RPL32\n",
       "4      5.177478e-130    0.633696  1.000  0.994  7.100394e-126        0   RPS14\n",
       "...              ...         ...    ...    ...            ...      ...     ...\n",
       "11624   9.164182e-03    4.822627  0.077  0.009   1.000000e+00        8    CDK2\n",
       "11625   9.201825e-03    2.670857  0.154  0.030   1.000000e+00        8  BCL2L1\n",
       "11626   9.334658e-03    2.912823  0.154  0.030   1.000000e+00        8    ETV6\n",
       "11627   9.838577e-03    3.310543  0.077  0.009   1.000000e+00        8    VWA8\n",
       "11628   9.946527e-03    2.067077  0.538  0.309   1.000000e+00        8   AP2M1\n",
       "\n",
       "[11629 rows x 7 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "path = \"../output/pbmc_markers.csv\"\n",
    "df1 = pd.read_csv(path)\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "c175e49e-8d3c-46ab-9444-740380a28aec",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "cell_marker_dict = {\"Naive CD4+ T\" : ['IL7R','CCR7'],\n",
    "              \"CD14+ Mono\" : [\"CD14\", \"LYZ\"],\n",
    "               \"Meomory CD4+\" : ['IL7R', 'S100A4'],\n",
    "               \"B\" : ['MS4A1'],\n",
    "               'CD8+ T' : ['CD8A'],\n",
    "               'FCGR3A+ Mono' : ['FCGR3A', 'MS4A7'],\n",
    "               'NK' : ['GNLY', 'NKG7'],\n",
    "               'DC' : ['RCER1A', 'CST3'],\n",
    "               'Platelet' : ['PPBP']\n",
    "              }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7e2ff749-feea-447b-9d0c-667f2d28e463",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "geneList = [\"IL7R\", \"CCR7\", \"CD14\",\"LYZ\", \"IL7R\", \"S100A4\", \"MS4A1\", \"CD8A\", \"FCGR3A\", \"MS4A7\", \"GNLY\", \"NKG7\", \"FCER1A\", \"CST3\", \"PPBP\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "aa1dac8d-fdcb-429b-8d2a-b194061e0c39",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cluster</th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1414</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>698</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>544</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>2507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>1140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>2536</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>624</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   cluster  size\n",
       "0        0   517\n",
       "1        1  1649\n",
       "2        2  1414\n",
       "3        3   698\n",
       "4        4   544\n",
       "5        5  2507\n",
       "6        6  1140\n",
       "7        7  2536\n",
       "8        8   624"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('cluster', as_index=False).size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "c5a56dea-f3cd-4338-9c91-6fb9f14495cb",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "cluster_0 = df[df['cluster'] == 0]\n",
    "cluster_1 = df[df['cluster'] == 1]\n",
    "cluster_2 = df[df['cluster'] == 2]\n",
    "cluster_3 = df[df['cluster'] == 3]\n",
    "cluster_4 = df[df['cluster'] == 4]\n",
    "cluster_5 = df[df['cluster'] == 5]\n",
    "cluster_6 = df[df['cluster'] == 6]\n",
    "cluster_7 = df[df['cluster'] == 7]\n",
    "cluster_8 = df[df['cluster'] == 8]\n",
    "df_list = [cluster_0, cluster_1, cluster_2, cluster_3, cluster_4, cluster_5, cluster_6, cluster_7, cluster_8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "2fc2a880-62b9-4239-9a6c-770d709ab30b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p_val</th>\n",
       "      <th>avg_log2FC</th>\n",
       "      <th>pct.1</th>\n",
       "      <th>pct.2</th>\n",
       "      <th>p_val_adj</th>\n",
       "      <th>cluster</th>\n",
       "      <th>gene</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.273332e-143</td>\n",
       "      <td>0.738706</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.991</td>\n",
       "      <td>1.746248e-139</td>\n",
       "      <td>0</td>\n",
       "      <td>RPS12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6.817653e-143</td>\n",
       "      <td>0.693452</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.995</td>\n",
       "      <td>9.349729e-139</td>\n",
       "      <td>0</td>\n",
       "      <td>RPS6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.661810e-141</td>\n",
       "      <td>0.737260</td>\n",
       "      <td>0.999</td>\n",
       "      <td>0.992</td>\n",
       "      <td>6.393206e-137</td>\n",
       "      <td>0</td>\n",
       "      <td>RPS27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8.158412e-138</td>\n",
       "      <td>0.626608</td>\n",
       "      <td>0.999</td>\n",
       "      <td>0.995</td>\n",
       "      <td>1.118845e-133</td>\n",
       "      <td>0</td>\n",
       "      <td>RPL32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.177478e-130</td>\n",
       "      <td>0.633696</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.994</td>\n",
       "      <td>7.100394e-126</td>\n",
       "      <td>0</td>\n",
       "      <td>RPS14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>512</th>\n",
       "      <td>9.642293e-03</td>\n",
       "      <td>0.630428</td>\n",
       "      <td>0.064</td>\n",
       "      <td>0.040</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>CTD-2336O2.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>513</th>\n",
       "      <td>9.651791e-03</td>\n",
       "      <td>1.583601</td>\n",
       "      <td>0.016</td>\n",
       "      <td>0.006</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>MTHFD1L</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>514</th>\n",
       "      <td>9.795989e-03</td>\n",
       "      <td>0.644169</td>\n",
       "      <td>0.029</td>\n",
       "      <td>0.054</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>RARS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>515</th>\n",
       "      <td>9.854458e-03</td>\n",
       "      <td>0.705814</td>\n",
       "      <td>0.225</td>\n",
       "      <td>0.186</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>GIMAP2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>516</th>\n",
       "      <td>9.872103e-03</td>\n",
       "      <td>0.776262</td>\n",
       "      <td>0.073</td>\n",
       "      <td>0.048</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>TBRG4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>517 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             p_val  avg_log2FC  pct.1  pct.2      p_val_adj  cluster  \\\n",
       "0    1.273332e-143    0.738706  1.000  0.991  1.746248e-139        0   \n",
       "1    6.817653e-143    0.693452  1.000  0.995  9.349729e-139        0   \n",
       "2    4.661810e-141    0.737260  0.999  0.992  6.393206e-137        0   \n",
       "3    8.158412e-138    0.626608  0.999  0.995  1.118845e-133        0   \n",
       "4    5.177478e-130    0.633696  1.000  0.994  7.100394e-126        0   \n",
       "..             ...         ...    ...    ...            ...      ...   \n",
       "512   9.642293e-03    0.630428  0.064  0.040   1.000000e+00        0   \n",
       "513   9.651791e-03    1.583601  0.016  0.006   1.000000e+00        0   \n",
       "514   9.795989e-03    0.644169  0.029  0.054   1.000000e+00        0   \n",
       "515   9.854458e-03    0.705814  0.225  0.186   1.000000e+00        0   \n",
       "516   9.872103e-03    0.776262  0.073  0.048   1.000000e+00        0   \n",
       "\n",
       "             gene  \n",
       "0           RPS12  \n",
       "1            RPS6  \n",
       "2           RPS27  \n",
       "3           RPL32  \n",
       "4           RPS14  \n",
       "..            ...  \n",
       "512  CTD-2336O2.1  \n",
       "513       MTHFD1L  \n",
       "514          RARS  \n",
       "515        GIMAP2  \n",
       "516         TBRG4  \n",
       "\n",
       "[517 rows x 7 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cluster_0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "2b1eb6c1-300b-4252-adfc-ec6bc55bcfa7",
   "metadata": {},
   "outputs": [],
   "source": [
    "def marker_result(exit):\n",
    "    for x in exit:\n",
    "        for cell, markerList in cell_marker_dict.items():\n",
    "            if x in markerList:\n",
    "                print('marker:',x, '    cell type:', cell)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "6eb14e62-1720-4d6b-b51f-e1dd69649c3e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marker: CCR7     cell type: Naive CD4+ T\n",
      "marker: IL7R     cell type: Naive CD4+ T\n",
      "marker: IL7R     cell type: Meomory CD4+\n"
     ]
    }
   ],
   "source": [
    "exit0 = [x for x in cluster_0['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "294952ad-c985-4d88-9395-e0896942961a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marker: CD14     cell type: CD14+ Mono\n",
      "marker: CST3     cell type: DC\n",
      "marker: LYZ     cell type: CD14+ Mono\n",
      "marker: S100A4     cell type: Meomory CD4+\n",
      "marker: MS4A7     cell type: FCGR3A+ Mono\n"
     ]
    }
   ],
   "source": [
    "exit1 = [x for x in cluster_1['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "7fe753fa-ae5a-4b17-9ce8-f00e6f8b56e2",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marker: IL7R     cell type: Naive CD4+ T\n",
      "marker: IL7R     cell type: Meomory CD4+\n"
     ]
    }
   ],
   "source": [
    "exit2 = [x for x in cluster_2['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "6d30e655-d582-49da-b3f8-8cfcef500f05",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marker: MS4A1     cell type: B\n"
     ]
    }
   ],
   "source": [
    "exit3 = [x for x in cluster_3['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "3b7ad83d-a904-4697-b0c9-718fc62f4493",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marker: NKG7     cell type: NK\n",
      "marker: CD8A     cell type: CD8+ T\n",
      "marker: GNLY     cell type: NK\n",
      "marker: IL7R     cell type: Naive CD4+ T\n",
      "marker: IL7R     cell type: Meomory CD4+\n"
     ]
    }
   ],
   "source": [
    "exit4 = [x for x in cluster_4['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "0cf283a7-118a-405a-82d2-e8e5baa7b63a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marker: MS4A7     cell type: FCGR3A+ Mono\n",
      "marker: FCGR3A     cell type: FCGR3A+ Mono\n",
      "marker: CST3     cell type: DC\n",
      "marker: S100A4     cell type: Meomory CD4+\n"
     ]
    }
   ],
   "source": [
    "exit5 = [x for x in cluster_5['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "8929ca65-e04c-4c52-926c-7ced64d403f5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marker: GNLY     cell type: NK\n",
      "marker: NKG7     cell type: NK\n",
      "marker: FCGR3A     cell type: FCGR3A+ Mono\n"
     ]
    }
   ],
   "source": [
    "exit6 = [x for x in cluster_6['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "ae11047a-b707-4d27-b8a8-8a902a06a0ff",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marker: CST3     cell type: DC\n",
      "marker: LYZ     cell type: CD14+ Mono\n"
     ]
    }
   ],
   "source": [
    "exit7 = [x for x in cluster_7['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "84745651-83fc-4448-9e2f-040a565feaf3",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "marker: PPBP     cell type: Platelet\n"
     ]
    }
   ],
   "source": [
    "exit8 = [x for x in cluster_8['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25777919-15f9-48b0-9a8b-042906f07eb6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "4fc1fcde-debd-46e3-af5d-91a7e042843f",
   "metadata": {},
   "outputs": [],
   "source": [
    "celltype_markers = {\n",
    "    # 造血干细胞及祖细胞\n",
    "    \"HSC\": [\"Lin-\", \"CD34+\", \"CD38-\", \"CD45RA-\", \"CD90+\"],\n",
    "    \"SPINK2+ HSPC\": [\"Lin-\", \"SPINK2+\", \"CD34+\"],\n",
    "    \"HSPC\": [\"Lin-\", \"SPINK2-\", \"CD34+\"],\n",
    "    \"GMP\": [\"Lin-\", \"CD34+\", \"CD38+\", \"CD90+\", \"CD45RA-\"],\n",
    "    \"GMP/Myeloblast\": [\"Lin-\", \"CD34+\", \"CD33+\"],\n",
    "    \"Early Myeloid Progenitor\": [\"CD33+\", \"MPO+\", \"CD11B-lo\"],\n",
    "    \"Intermediate Myeloid\": [\"CD33-mid\", \"MPO-mid\", \"CD11B+\"],\n",
    "    \"Mature Myeloid\": [\"CD33-lo\", \"MPO-lo\", \"CD11B+\", \"CD141+\"],\n",
    "    \n",
    "    # 髓系细胞\n",
    "    \"Monocytes\": [\"CD14+\"],\n",
    "    \"Non-Classical Monocyte\": [\"CD14-lo\", \"CD11C+\", \"HLA-DR++\"],\n",
    "    \"Macrophages\": [\"VCAM1+\", \"CD68+\", \"CD163+\"],\n",
    "    \"pDC\": [\"CD123+\", \"CD34-\"],\n",
    "    \n",
    "    # 淋系细胞\n",
    "    \"CLP\": [\"Lin-\", \"CD34+\", \"CD38-\", \"CD45RA+\"],\n",
    "    \"Immature_B_Cell\": [\"Pax5+\", \"CD79A+\", \"CD38-lo/mid\"],\n",
    "    \"B-Cells\": [\"Pax5-\", \"CD79A+\", \"CD38-lo/mid\"],\n",
    "    \"CD4+ T-Cell\": [\"CD3e+\", \"CD4+\"],\n",
    "    \"CD8+ T-Cell\": [\"CD3e+\", \"CD8+\"],\n",
    "    \"Plasma Cells\": [\"CD79A+\", \"CD38+++\", \"CD138+\"],\n",
    "    \n",
    "    # 红系/巨核系\n",
    "    \"MEP/Early Erythroblast\": [\"Lin-\", \"CD34+\", \"GATA1+\"],\n",
    "    \"CD34+ CD61+\": [\"Lin-\", \"CD34+\", \"CD61+\"],\n",
    "    \"Erythroblast\": [\"GATA1+\", \"CD71+\", \"GYPC+\"],\n",
    "    \"Erythroid\": [\"GYPC+\", \"CD71+\"],\n",
    "    \"GATA1neg_Mks\": [\"GATA1-\", \"CD61+\", \"TGFB1+\"],\n",
    "    \"GATA1pos_Mks\": [\"GATA1+\", \"CD61+\", \"TGFB1+\"],\n",
    "    \n",
    "    # 间充质/基质细胞\n",
    "    \"Adipo-MSC\": [\"FOXC1+\", \"CXCL12+\", \"CD90-lo\"],\n",
    "    \"THY1+ MSC\": [\"FOXC1+\", \"CXCL12+\", \"CD90-hi\"],\n",
    "    \"Adipocyte\": [\"CD146+\", \"CD138+\"],\n",
    "    \"Endosteal\": [\"CD56+\", \"VIM+\", \"cluster spatial location\"],\n",
    "    \"AEC\": [\"CXCL12+\", \"VE-Cadherin+\"],\n",
    "    \"SEC\": [\"VE-Cadherin+\", \"CD34+\", \"CXCL12-\"],\n",
    "    \"VSMC\": [\"ASMA+\", \"VE-Cadherin-\"],\n",
    "    \"Schwann Cell\": [\"PLP1+\", \"CD271+\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "9ca03c7a-10cd-4239-af56-9033ee8be83b",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['HSC',\n",
       " 'SPINK2+ HSPC',\n",
       " 'HSPC',\n",
       " 'GMP',\n",
       " 'GMP/Myeloblast',\n",
       " 'Early Myeloid Progenitor',\n",
       " 'Intermediate Myeloid',\n",
       " 'Mature Myeloid',\n",
       " 'Monocytes',\n",
       " 'Non-Classical Monocyte',\n",
       " 'Macrophages',\n",
       " 'pDC',\n",
       " 'CLP',\n",
       " 'Immature_B_Cell',\n",
       " 'B-Cells',\n",
       " 'CD4+ T-Cell',\n",
       " 'CD8+ T-Cell',\n",
       " 'Plasma Cells',\n",
       " 'MEP/Early Erythroblast',\n",
       " 'CD34+ CD61+',\n",
       " 'Erythroblast',\n",
       " 'Erythroid',\n",
       " 'GATA1neg_Mks',\n",
       " 'GATA1pos_Mks',\n",
       " 'Adipo-MSC',\n",
       " 'THY1+ MSC',\n",
       " 'Adipocyte',\n",
       " 'Endosteal',\n",
       " 'AEC',\n",
       " 'SEC',\n",
       " 'VSMC',\n",
       " 'Schwann Cell']"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(celltype_markers.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "4e270cf4-1e30-40f0-882c-fab3a19a4b24",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "32"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(list(celltype_markers.keys()))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "748176b7-e40e-40b7-b56f-9569557a1227",
   "metadata": {},
   "source": [
    "# cell paper data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "723882df-005d-4f60-9e7d-dc6421432bbf",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>p_val</th>\n",
       "      <th>avg_log2FC</th>\n",
       "      <th>pct.1</th>\n",
       "      <th>pct.2</th>\n",
       "      <th>p_val_adj</th>\n",
       "      <th>cluster</th>\n",
       "      <th>gene</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>PLAUR</td>\n",
       "      <td>6.897701e-132</td>\n",
       "      <td>2.149424</td>\n",
       "      <td>0.747</td>\n",
       "      <td>0.232</td>\n",
       "      <td>2.031166e-127</td>\n",
       "      <td>0</td>\n",
       "      <td>PLAUR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MMP9</td>\n",
       "      <td>3.296950e-126</td>\n",
       "      <td>2.649203</td>\n",
       "      <td>0.625</td>\n",
       "      <td>0.110</td>\n",
       "      <td>9.708527e-122</td>\n",
       "      <td>0</td>\n",
       "      <td>MMP9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>CXCL8</td>\n",
       "      <td>5.546704e-124</td>\n",
       "      <td>1.903409</td>\n",
       "      <td>0.743</td>\n",
       "      <td>0.208</td>\n",
       "      <td>1.633338e-119</td>\n",
       "      <td>0</td>\n",
       "      <td>CXCL8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>S100A12</td>\n",
       "      <td>7.318006e-124</td>\n",
       "      <td>2.325037</td>\n",
       "      <td>0.726</td>\n",
       "      <td>0.190</td>\n",
       "      <td>2.154933e-119</td>\n",
       "      <td>0</td>\n",
       "      <td>S100A12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>IL1R2</td>\n",
       "      <td>5.509395e-87</td>\n",
       "      <td>2.637322</td>\n",
       "      <td>0.485</td>\n",
       "      <td>0.088</td>\n",
       "      <td>1.622352e-82</td>\n",
       "      <td>0</td>\n",
       "      <td>IL1R2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32524</th>\n",
       "      <td>XYLT1.25</td>\n",
       "      <td>8.909273e-03</td>\n",
       "      <td>-5.092875</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.163</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>34</td>\n",
       "      <td>XYLT1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32525</th>\n",
       "      <td>ERG.32</td>\n",
       "      <td>9.152692e-03</td>\n",
       "      <td>-5.948849</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.175</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>34</td>\n",
       "      <td>ERG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32526</th>\n",
       "      <td>IGHGP.18</td>\n",
       "      <td>9.633257e-03</td>\n",
       "      <td>-3.281192</td>\n",
       "      <td>0.086</td>\n",
       "      <td>0.300</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>34</td>\n",
       "      <td>IGHGP</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32527</th>\n",
       "      <td>CLIC4.21</td>\n",
       "      <td>9.770379e-03</td>\n",
       "      <td>-3.403591</td>\n",
       "      <td>0.029</td>\n",
       "      <td>0.242</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>34</td>\n",
       "      <td>CLIC4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32528</th>\n",
       "      <td>HLA-DPB1.27</td>\n",
       "      <td>9.921536e-03</td>\n",
       "      <td>-5.434610</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.148</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>34</td>\n",
       "      <td>HLA-DPB1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>32529 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        Unnamed: 0          p_val  avg_log2FC  pct.1  pct.2      p_val_adj  \\\n",
       "0            PLAUR  6.897701e-132    2.149424  0.747  0.232  2.031166e-127   \n",
       "1             MMP9  3.296950e-126    2.649203  0.625  0.110  9.708527e-122   \n",
       "2            CXCL8  5.546704e-124    1.903409  0.743  0.208  1.633338e-119   \n",
       "3          S100A12  7.318006e-124    2.325037  0.726  0.190  2.154933e-119   \n",
       "4            IL1R2   5.509395e-87    2.637322  0.485  0.088   1.622352e-82   \n",
       "...            ...            ...         ...    ...    ...            ...   \n",
       "32524     XYLT1.25   8.909273e-03   -5.092875  0.000  0.163   1.000000e+00   \n",
       "32525       ERG.32   9.152692e-03   -5.948849  0.000  0.175   1.000000e+00   \n",
       "32526     IGHGP.18   9.633257e-03   -3.281192  0.086  0.300   1.000000e+00   \n",
       "32527     CLIC4.21   9.770379e-03   -3.403591  0.029  0.242   1.000000e+00   \n",
       "32528  HLA-DPB1.27   9.921536e-03   -5.434610  0.000  0.148   1.000000e+00   \n",
       "\n",
       "       cluster      gene  \n",
       "0            0     PLAUR  \n",
       "1            0      MMP9  \n",
       "2            0     CXCL8  \n",
       "3            0   S100A12  \n",
       "4            0     IL1R2  \n",
       "...        ...       ...  \n",
       "32524       34     XYLT1  \n",
       "32525       34       ERG  \n",
       "32526       34     IGHGP  \n",
       "32527       34     CLIC4  \n",
       "32528       34  HLA-DPB1  \n",
       "\n",
       "[32529 rows x 8 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd \n",
    "path_3000 = \"../../2024paper/output/SB66_combined_markers_3000_ident1000_20250728.csv\"\n",
    "path = \"../../2024paper/output/SB66_combined_markers_2000_ident1000_20250725.csv\"\n",
    "# path = \"/lustre/home/acct-medfzx/medfzx-lkw/project/bone/2024paper/output/SB66_combined_markers_2000_ident1000_20250725.csv\"\n",
    "df = pd.read_csv(path)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b22e55af-7157-4f85-883a-db9f683d5d7b",
   "metadata": {},
   "outputs": [],
   "source": [
    "markers_list <- list(\n",
    "  # 造血干细胞及祖细胞\n",
    "  HSC = c(\"Lin-\", \"CD34+\", \"CD38-\", \"CD45RA-\", \"CD90+\"),\n",
    "  SPINK2_HSPC = c(\"Lin-\", \"SPINK2+\", \"CD34+\"),\n",
    "  HSPC = c(\"Lin-\", \"SPINK2-\", \"CD34+\"),\n",
    "  GMP = c(\"Lin-\", \"CD34+\", \"CD38+\", \"CD90+\", \"CD45RA-\"),\n",
    "  GMP_Myeloblast = c(\"Lin-\", \"CD34+\", \"CD33+\"),\n",
    "  Early_Myeloid_Progenitor = c(\"CD33+\", \"MPO+\", \"CD11B-lo\"),\n",
    "  Intermediate_Myeloid = c(\"CD33-mid\", \"MPO-mid\", \"CD11B+\"),\n",
    "  Mature_Myeloid = c(\"CD33-lo\", \"MPO-lo\", \"CD11B+\", \"CD141+\"),\n",
    "  \n",
    "  # 髓系细胞    一大类免疫细胞，起源于骨髓中的​​共同髓系祖细胞（CMP）​​，参与先天免疫、炎症反应和组织稳态维持  \n",
    "  Monocytes = c(\"CD14+\"),   ## ​​经典单核细胞（CD14hiCD16-）​​：占90%，高吞噬活性，参与急性炎症反应   非经典单核细胞（CD14-loCD16+）​​：巡逻血管内皮，监测病原体并参与抗病毒反应\n",
    "  Non_Classical_Monocyte = c(\"CD14-lo\", \"CD11C+\", \"HLA-DR++\"),   # \n",
    "  Macrophages = c(\"VCAM1+\", \"CD68+\", \"CD163+\"),   # ​​组织特异性​​：如肝脏库普弗细胞、脑小胶质细胞等，均源自胚胎或单核细胞分化\n",
    "  pDC = c(\"CD123+\", \"CD34-\"),\n",
    "  \n",
    "  # 淋系细胞\n",
    "  CLP = c(\"Lin-\", \"CD34+\", \"CD38-\", \"CD45RA+\"),\n",
    "  Immature_B_Cell = c(\"Pax5+\", \"CD79A+\", \"CD38-lo/mid\"),\n",
    "  B_Cells = c(\"Pax5-\", \"CD79A+\", \"CD38-lo/mid\"),\n",
    "  CD4_T_Cell = c(\"CD3e+\", \"CD4+\"),\n",
    "  CD8_T_Cell = c(\"CD3e+\", \"CD8+\"),\n",
    "  Plasma_Cells = c(\"CD79A+\", \"CD38+++\", \"CD138+\"),\n",
    "  \n",
    "  # 红系/巨核系\n",
    "  MEP_Early_Erythroblast = c(\"Lin-\", \"CD34+\", \"GATA1+\"),\n",
    "  CD34_CD61 = c(\"Lin-\", \"CD34+\", \"CD61+\"),\n",
    "  Erythroblast = c(\"GATA1+\", \"CD71+\", \"GYPC+\"),\n",
    "  Erythroid = c(\"GYPC+\", \"CD71+\"),\n",
    "  GATA1neg_Mks = c(\"GATA1-\", \"CD61+\", \"TGFB1+\"),\n",
    "  GATA1pos_Mks = c(\"GATA1+\", \"CD61+\", \"TGFB1+\"),\n",
    "  \n",
    "  # 间充质/基质细胞\n",
    "  Adipo_MSC = c(\"FOXC1+\", \"CXCL12+\", \"CD90-lo\"),\n",
    "  THY1_MSC = c(\"FOXC1+\", \"CXCL12+\", \"CD90-hi\"),\n",
    "  Adipocyte = c(\"CD146+\", \"CD138+\"),\n",
    "  Endosteal = c(\"CD56+\", \"VIM+\", \"cluster spatial location\"),\n",
    "  AEC = c(\"CXCL12+\", \"VE-Cadherin+\"),\n",
    "  SEC = c(\"VE-Cadherin+\", \"CD34+\", \"CXCL12-\"),\n",
    "  VSMC = c(\"ASMA+\", \"VE-Cadherin-\"),\n",
    "  Schwann_Cell = c(\"PLP1+\", \"CD271+\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "id": "21127758-68f2-42cd-862a-9f80f0cd1f02",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "markers_dict = {\n",
    "    # 造血干细胞及祖细胞\n",
    "    \"HSC\": [\"Lin\", \"CD34\", \"CD38\", \"PTPRC\", \"THY1\"],\n",
    "    \"SPINK2_HSPC\": [\"Lin\", \"SPINK2\", \"CD34\"],\n",
    "    \"HSPC\": [\"Lin\", \"SPINK2\", \"CD34\"],\n",
    "    \"GMP\": [\"Lin\", \"CD34\", \"CD38\", \"THY1\", \"PTPRC\"],\n",
    "    \"GMP_Myeloblast\": [\"Lin\", \"CD34\", \"CD33\"],\n",
    "    \"Early_Myeloid_Progenitor\": [\"CD33\", \"MPO\", \"ITGAM\"],\n",
    "    \"Intermediate_Myeloid\": [\"CD33\", \"MPO\", \"ITGAM\"],\n",
    "    \"Mature_Myeloid\": [\"CD33\", \"MPO\", \"ITGAM\", \"THBD\"],\n",
    "    \n",
    "    # 髓系细胞\n",
    "    \"Monocytes\": [\"CD14\"],\n",
    "    \"Non_Classical_Monocyte\": [\"CD14\", \"ITGAX\", \"HLA-DRA\"],\n",
    "    \"Macrophages\": [\"VCAM1\", \"CD68\", \"CD163\"],\n",
    "    \"pDC\": [\"IL3RA\", \"CD34\"],\n",
    "    \n",
    "    # 淋系细胞\n",
    "    \"CLP\": [\"Lin\", \"CD34\", \"CD38\", \"PTPRC\"],\n",
    "    \"Immature_B_Cell\": [\"PAX5\", \"CD79A\", \"CD38\"],\n",
    "    \"B_Cells\": [\"PAX5\", \"CD79A\", \"CD38\"],\n",
    "    \"CD4_T_Cell\": [\"CD3E\", \"CD4\"],\n",
    "    \"CD8_T_Cell\": [\"CD3E\", \"CD8A\"],\n",
    "    \"Plasma_Cells\": [\"CD79A\", \"CD38\", \"SDC1\"],\n",
    "    \n",
    "    # 红系/巨核系\n",
    "    \"MEP_Early_Erythroblast\": [\"Lin\", \"CD34\", \"GATA1\"],\n",
    "    \"CD34_CD61\": [\"Lin\", \"CD34\", \"ITGB3\"],\n",
    "    \"Erythroblast\": [\"GATA1\", \"TFRC\", \"GYPC\"],\n",
    "    \"Erythroid\": [\"GYPC\", \"TFRC\"],\n",
    "    \"GATA1neg_Mks\": [\"GATA1\", \"ITGB3\", \"TGFB1\"],\n",
    "    \"GATA1pos_Mks\": [\"GATA1\", \"ITGB3\", \"TGFB1\"],\n",
    "    \n",
    "    # 间充质/基质细胞\n",
    "    \"Adipo_MSC\": [\"FOXC1\", \"CXCL12\", \"THY1\"],\n",
    "    \"THY1_MSC\": [\"FOXC1\", \"CXCL12\", \"THY1\"],\n",
    "    \"Adipocyte\": [\"MCAM\", \"SDC1\"],\n",
    "    \"Endosteal\": [\"NCAM1\", \"VIM\", \"cluster_spatial_location\"],\n",
    "    \"AEC\": [\"CXCL12\", \"CDH5\"],\n",
    "    \"SEC\": [\"CDH5\", \"CD34\", \"CXCL12\"],\n",
    "    \"VSMC\": [\"ACTA2\", \"CDH5\"],\n",
    "    \"Schwann_Cell\": [\"PLP1\", \"NGFR\"]\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "83f5de4f-a3da-4ca3-b443-c5b5c02b90e5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "37"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unique_genes = list({\n",
    "    gene for markers in markers_dict.values() \n",
    "    for gene in markers \n",
    "    if not gene.startswith('cluster')  # 排除空间位置标记\n",
    "}) \n",
    "\n",
    "len(unique_genes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "id": "efe44cb9-3e10-4daf-a929-fb50980b9800",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cluster</th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11</td>\n",
       "      <td>450</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>12</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>13</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>14</td>\n",
       "      <td>450</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>15</td>\n",
       "      <td>168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>16</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>17</td>\n",
       "      <td>268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>18</td>\n",
       "      <td>180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>19</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20</td>\n",
       "      <td>172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>21</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>22</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>23</td>\n",
       "      <td>387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>24</td>\n",
       "      <td>531</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>25</td>\n",
       "      <td>176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>26</td>\n",
       "      <td>438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>27</td>\n",
       "      <td>386</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>28</td>\n",
       "      <td>182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>29</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>30</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>31</td>\n",
       "      <td>202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>32</td>\n",
       "      <td>491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>33</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>34</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    cluster  size\n",
       "0         0    41\n",
       "1         1    75\n",
       "2         2    38\n",
       "3         3    55\n",
       "4         4    26\n",
       "5         5   228\n",
       "6         6   192\n",
       "7         7   621\n",
       "8         8   135\n",
       "9         9    49\n",
       "10       10   104\n",
       "11       11   450\n",
       "12       12   141\n",
       "13       13    60\n",
       "14       14   450\n",
       "15       15   168\n",
       "16       16    28\n",
       "17       17   268\n",
       "18       18   180\n",
       "19       19    78\n",
       "20       20   172\n",
       "21       21    84\n",
       "22       22   357\n",
       "23       23   387\n",
       "24       24   531\n",
       "25       25   176\n",
       "26       26   438\n",
       "27       27   386\n",
       "28       28   182\n",
       "29       29   200\n",
       "30       30    42\n",
       "31       31   202\n",
       "32       32   491\n",
       "33       33    94\n",
       "34       34   200"
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df[df['avg_log2FC'] > 1]\n",
    "\n",
    "df.groupby('cluster', as_index=False).size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "id": "4afab5c0-6fa4-4be3-b205-7de40e719ea6",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "cluster_0= df[df['cluster'] == 0]\n",
    "cluster_1= df[df['cluster'] == 1]\n",
    "cluster_2= df[df['cluster'] == 2]\n",
    "cluster_3= df[df['cluster'] == 3]\n",
    "cluster_4= df[df['cluster'] == 4]\n",
    "cluster_5= df[df['cluster'] == 5]\n",
    "cluster_6= df[df['cluster'] == 6]\n",
    "cluster_7= df[df['cluster'] == 7]\n",
    "cluster_8= df[df['cluster'] == 8]\n",
    "cluster_9= df[df['cluster'] == 9]\n",
    "cluster_10= df[df['cluster'] == 10]\n",
    "cluster_11= df[df['cluster'] == 11]\n",
    "cluster_12= df[df['cluster'] == 12]\n",
    "cluster_13= df[df['cluster'] == 13]\n",
    "cluster_14= df[df['cluster'] == 14]\n",
    "cluster_15= df[df['cluster'] == 15]\n",
    "cluster_16= df[df['cluster'] == 16]\n",
    "cluster_17= df[df['cluster'] == 17]\n",
    "cluster_18= df[df['cluster'] == 18]\n",
    "cluster_19= df[df['cluster'] == 19]\n",
    "cluster_20= df[df['cluster'] == 20]\n",
    "cluster_21= df[df['cluster'] == 21]\n",
    "cluster_22= df[df['cluster'] == 22]\n",
    "cluster_23= df[df['cluster'] == 23]\n",
    "cluster_24= df[df['cluster'] == 24]\n",
    "cluster_25= df[df['cluster'] == 25]\n",
    "cluster_26= df[df['cluster'] == 26]\n",
    "cluster_27= df[df['cluster'] == 27]\n",
    "cluster_28= df[df['cluster'] == 28]\n",
    "cluster_29= df[df['cluster'] == 29]\n",
    "cluster_30= df[df['cluster'] == 30]\n",
    "cluster_31= df[df['cluster'] == 31]\n",
    "cluster_32= df[df['cluster'] == 32]\n",
    "cluster_33= df[df['cluster'] == 33]\n",
    "cluster_34= df[df['cluster'] == 34]\n",
    "\n",
    "df_list = [cluster_0, cluster_1, cluster_2, cluster_3, cluster_4, cluster_5, cluster_6, cluster_7, cluster_8, cluster_9, cluster_10, cluster_11, cluster_12, cluster_13,cluster_14,cluster_15,cluster_16,cluster_17,cluster_18,cluster_19,cluster_20,cluster_21,cluster_22,cluster_23,cluster_24,cluster_25,cluster_26,cluster_27,cluster_28,cluster_29,cluster_30,cluster_31,cluster_32,cluster_33,cluster_34]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "3d7cd1ed-9c15-4275-8d37-66a6e6eacf56",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cluster_0= df[df['cluster'] == 0]\n",
      "cluster_1= df[df['cluster'] == 1]\n",
      "cluster_2= df[df['cluster'] == 2]\n",
      "cluster_3= df[df['cluster'] == 3]\n",
      "cluster_4= df[df['cluster'] == 4]\n",
      "cluster_5= df[df['cluster'] == 5]\n",
      "cluster_6= df[df['cluster'] == 6]\n",
      "cluster_7= df[df['cluster'] == 7]\n",
      "cluster_8= df[df['cluster'] == 8]\n",
      "cluster_9= df[df['cluster'] == 9]\n",
      "cluster_10= df[df['cluster'] == 10]\n",
      "cluster_11= df[df['cluster'] == 11]\n",
      "cluster_12= df[df['cluster'] == 12]\n",
      "cluster_13= df[df['cluster'] == 13]\n",
      "cluster_14= df[df['cluster'] == 14]\n",
      "cluster_15= df[df['cluster'] == 15]\n",
      "cluster_16= df[df['cluster'] == 16]\n",
      "cluster_17= df[df['cluster'] == 17]\n",
      "cluster_18= df[df['cluster'] == 18]\n",
      "cluster_19= df[df['cluster'] == 19]\n",
      "cluster_20= df[df['cluster'] == 20]\n",
      "cluster_21= df[df['cluster'] == 21]\n",
      "cluster_22= df[df['cluster'] == 22]\n",
      "cluster_23= df[df['cluster'] == 23]\n",
      "cluster_24= df[df['cluster'] == 24]\n",
      "cluster_25= df[df['cluster'] == 25]\n",
      "cluster_26= df[df['cluster'] == 26]\n",
      "cluster_27= df[df['cluster'] == 27]\n",
      "cluster_28= df[df['cluster'] == 28]\n",
      "cluster_29= df[df['cluster'] == 29]\n",
      "cluster_30= df[df['cluster'] == 30]\n",
      "cluster_31= df[df['cluster'] == 31]\n",
      "cluster_32= df[df['cluster'] == 32]\n",
      "cluster_33= df[df['cluster'] == 33]\n",
      "cluster_34= df[df['cluster'] == 34]\n"
     ]
    }
   ],
   "source": [
    "for i in range(35):\n",
    "    print('cluster_', str(i), \"= df[df['cluster'] == \", str(i)  + \"]\",sep='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 260,
   "id": "639bf553-6b4f-4d19-88f3-0e1efef22671",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>p_val</th>\n",
       "      <th>avg_log2FC</th>\n",
       "      <th>pct.1</th>\n",
       "      <th>pct.2</th>\n",
       "      <th>p_val_adj</th>\n",
       "      <th>cluster</th>\n",
       "      <th>gene</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>PLAUR</td>\n",
       "      <td>6.897701e-132</td>\n",
       "      <td>2.149424</td>\n",
       "      <td>0.747</td>\n",
       "      <td>0.232</td>\n",
       "      <td>2.031166e-127</td>\n",
       "      <td>0</td>\n",
       "      <td>PLAUR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MMP9</td>\n",
       "      <td>3.296950e-126</td>\n",
       "      <td>2.649203</td>\n",
       "      <td>0.625</td>\n",
       "      <td>0.110</td>\n",
       "      <td>9.708527e-122</td>\n",
       "      <td>0</td>\n",
       "      <td>MMP9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>CXCL8</td>\n",
       "      <td>5.546704e-124</td>\n",
       "      <td>1.903409</td>\n",
       "      <td>0.743</td>\n",
       "      <td>0.208</td>\n",
       "      <td>1.633338e-119</td>\n",
       "      <td>0</td>\n",
       "      <td>CXCL8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>S100A12</td>\n",
       "      <td>7.318006e-124</td>\n",
       "      <td>2.325037</td>\n",
       "      <td>0.726</td>\n",
       "      <td>0.190</td>\n",
       "      <td>2.154933e-119</td>\n",
       "      <td>0</td>\n",
       "      <td>S100A12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>IL1R2</td>\n",
       "      <td>5.509395e-87</td>\n",
       "      <td>2.637322</td>\n",
       "      <td>0.485</td>\n",
       "      <td>0.088</td>\n",
       "      <td>1.622352e-82</td>\n",
       "      <td>0</td>\n",
       "      <td>IL1R2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1099</th>\n",
       "      <td>ERN1</td>\n",
       "      <td>1.376329e-03</td>\n",
       "      <td>0.333521</td>\n",
       "      <td>0.104</td>\n",
       "      <td>0.177</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>ERN1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1135</th>\n",
       "      <td>GALC</td>\n",
       "      <td>2.710828e-03</td>\n",
       "      <td>1.279758</td>\n",
       "      <td>0.106</td>\n",
       "      <td>0.070</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>GALC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1139</th>\n",
       "      <td>ZFAND2A</td>\n",
       "      <td>3.037529e-03</td>\n",
       "      <td>0.404057</td>\n",
       "      <td>0.049</td>\n",
       "      <td>0.086</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>ZFAND2A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1172</th>\n",
       "      <td>PHLDB2</td>\n",
       "      <td>7.590729e-03</td>\n",
       "      <td>0.984759</td>\n",
       "      <td>0.032</td>\n",
       "      <td>0.054</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>PHLDB2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1173</th>\n",
       "      <td>TNNI2</td>\n",
       "      <td>7.901774e-03</td>\n",
       "      <td>1.447355</td>\n",
       "      <td>0.027</td>\n",
       "      <td>0.010</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>0</td>\n",
       "      <td>TNNI2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>61 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Unnamed: 0          p_val  avg_log2FC  pct.1  pct.2      p_val_adj  \\\n",
       "0         PLAUR  6.897701e-132    2.149424  0.747  0.232  2.031166e-127   \n",
       "1          MMP9  3.296950e-126    2.649203  0.625  0.110  9.708527e-122   \n",
       "2         CXCL8  5.546704e-124    1.903409  0.743  0.208  1.633338e-119   \n",
       "3       S100A12  7.318006e-124    2.325037  0.726  0.190  2.154933e-119   \n",
       "4         IL1R2   5.509395e-87    2.637322  0.485  0.088   1.622352e-82   \n",
       "...         ...            ...         ...    ...    ...            ...   \n",
       "1099       ERN1   1.376329e-03    0.333521  0.104  0.177   1.000000e+00   \n",
       "1135       GALC   2.710828e-03    1.279758  0.106  0.070   1.000000e+00   \n",
       "1139    ZFAND2A   3.037529e-03    0.404057  0.049  0.086   1.000000e+00   \n",
       "1172     PHLDB2   7.590729e-03    0.984759  0.032  0.054   1.000000e+00   \n",
       "1173      TNNI2   7.901774e-03    1.447355  0.027  0.010   1.000000e+00   \n",
       "\n",
       "      cluster     gene  \n",
       "0           0    PLAUR  \n",
       "1           0     MMP9  \n",
       "2           0    CXCL8  \n",
       "3           0  S100A12  \n",
       "4           0    IL1R2  \n",
       "...       ...      ...  \n",
       "1099        0     ERN1  \n",
       "1135        0     GALC  \n",
       "1139        0  ZFAND2A  \n",
       "1172        0   PHLDB2  \n",
       "1173        0    TNNI2  \n",
       "\n",
       "[61 rows x 8 columns]"
      ]
     },
     "execution_count": 260,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cluster_0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "id": "bdc3d080-e49b-49e3-bf76-1f2ed69ff516",
   "metadata": {},
   "outputs": [],
   "source": [
    "def marker_result(exit):\n",
    "    count = 0\n",
    "    for x in exit:\n",
    "        for cell, markerList in markers_dict.items():\n",
    "            if x in markerList:\n",
    "                count += 1\n",
    "                print(count, 'marker:',x, '    cell type:', cell)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 246,
   "id": "29b455cb-5f77-42cd-904d-1d692485b94d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: ITGAX     cell type: Non_Classical_Monocyte\n"
     ]
    }
   ],
   "source": [
    "geneList = unique_genes\n",
    "cluster_0= df[df['cluster'] == 0]\n",
    "cluster_0 = cluster_0[cluster_0['avg_log2FC'] > 0.25]\n",
    "exit = [x for x in cluster_0['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 248,
   "id": "9d01d1f6-7074-4d08-8060-eb00131bc05e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: ITGAX     cell type: Non_Classical_Monocyte\n",
      "2 marker: CD14     cell type: Monocytes\n",
      "3 marker: CD14     cell type: Non_Classical_Monocyte\n"
     ]
    }
   ],
   "source": [
    "cluster_1 = df[df['cluster'] == 1]\n",
    "cluster_1 = cluster_1[cluster_1['avg_log2FC'] > 0.25]\n",
    "exit = [x for x in cluster_1['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 234,
   "id": "9f771a2c-fdb5-4c6a-b38d-fcf3e5d66d9d",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "cluster_2= df[df['cluster'] == 2]\n",
    "cluster_2 = cluster_2[cluster_2['avg_log2FC'] > 0.25]\n",
    "\n",
    "exit = [x for x in cluster_2['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 249,
   "id": "d6b2c84a-43b7-4a91-abfe-01b1f27e9bc6",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: MPO     cell type: Early_Myeloid_Progenitor\n",
      "2 marker: MPO     cell type: Intermediate_Myeloid\n",
      "3 marker: MPO     cell type: Mature_Myeloid\n",
      "4 marker: TFRC     cell type: Erythroblast\n",
      "5 marker: TFRC     cell type: Erythroid\n"
     ]
    }
   ],
   "source": [
    "cluster_3= df[df['cluster'] == 3]\n",
    "cluster_3 = cluster_3[cluster_3['avg_log2FC'] >0.25]\n",
    "exit = [x for x in cluster_3['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 259,
   "id": "7d740111-ebdd-4392-8415-b8cc87c3ede7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: ITGAX     cell type: Non_Classical_Monocyte\n",
      "2 marker: CD79A     cell type: Immature_B_Cell\n",
      "3 marker: CD79A     cell type: B_Cells\n",
      "4 marker: CD79A     cell type: Plasma_Cells\n",
      "5 marker: HLA-DRA     cell type: Non_Classical_Monocyte\n",
      "6 marker: NCAM1     cell type: Endosteal\n",
      "7 marker: CXCL12     cell type: Adipo_MSC\n",
      "8 marker: CXCL12     cell type: THY1_MSC\n",
      "9 marker: CXCL12     cell type: AEC\n",
      "10 marker: CXCL12     cell type: SEC\n",
      "11 marker: VCAM1     cell type: Macrophages\n",
      "12 marker: PAX5     cell type: Immature_B_Cell\n",
      "13 marker: PAX5     cell type: B_Cells\n",
      "14 marker: SPINK2     cell type: SPINK2_HSPC\n",
      "15 marker: SPINK2     cell type: HSPC\n",
      "16 marker: THY1     cell type: HSC\n",
      "17 marker: THY1     cell type: GMP\n",
      "18 marker: THY1     cell type: Adipo_MSC\n",
      "19 marker: THY1     cell type: THY1_MSC\n",
      "20 marker: MCAM     cell type: Adipocyte\n",
      "21 marker: CD14     cell type: Monocytes\n",
      "22 marker: CD14     cell type: Non_Classical_Monocyte\n",
      "23 marker: CD8A     cell type: CD8_T_Cell\n",
      "24 marker: ACTA2     cell type: VSMC\n",
      "25 marker: IL3RA     cell type: pDC\n",
      "26 marker: THBD     cell type: Mature_Myeloid\n"
     ]
    }
   ],
   "source": [
    "cluster_4= df[df['cluster'] == 4]\n",
    "# cluster_4 = cluster_4[cluster_4['avg_log2FC'] > 0.000]\n",
    "exit = [x for x in cluster_4['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "id": "34f07808-10ea-4e6e-948f-e752eb8dfbd8",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: CD79A     cell type: Immature_B_Cell\n",
      "2 marker: CD79A     cell type: B_Cells\n",
      "3 marker: CD79A     cell type: Plasma_Cells\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_5['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "id": "8022d5ee-7b7b-4c66-91d7-7597a9fb14c5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: HLA-DRA     cell type: Non_Classical_Monocyte\n",
      "2 marker: MPO     cell type: Early_Myeloid_Progenitor\n",
      "3 marker: MPO     cell type: Intermediate_Myeloid\n",
      "4 marker: MPO     cell type: Mature_Myeloid\n",
      "5 marker: SPINK2     cell type: SPINK2_HSPC\n",
      "6 marker: SPINK2     cell type: HSPC\n",
      "7 marker: TFRC     cell type: Erythroblast\n",
      "8 marker: TFRC     cell type: Erythroid\n",
      "9 marker: IL3RA     cell type: pDC\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_6['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "id": "81b2883f-2c38-4e2c-8767-47013bd27a59",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: CXCL12     cell type: Adipo_MSC\n",
      "2 marker: CXCL12     cell type: THY1_MSC\n",
      "3 marker: CXCL12     cell type: AEC\n",
      "4 marker: CXCL12     cell type: SEC\n",
      "5 marker: VCAM1     cell type: Macrophages\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_7['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "id": "e3c0133a-91ed-413f-b7f9-3a26ab6639fd",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: CD79A     cell type: Immature_B_Cell\n",
      "2 marker: CD79A     cell type: B_Cells\n",
      "3 marker: CD79A     cell type: Plasma_Cells\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_8['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "id": "6a033d61-5900-4e72-a508-4f0b333e1697",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: TFRC     cell type: Erythroblast\n",
      "2 marker: TFRC     cell type: Erythroid\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_9['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "id": "b5aa8adc-73e1-4841-8ee7-dad10db4ef60",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: CXCL12     cell type: Adipo_MSC\n",
      "2 marker: CXCL12     cell type: THY1_MSC\n",
      "3 marker: CXCL12     cell type: AEC\n",
      "4 marker: CXCL12     cell type: SEC\n",
      "5 marker: ACTA2     cell type: VSMC\n",
      "6 marker: THY1     cell type: HSC\n",
      "7 marker: THY1     cell type: GMP\n",
      "8 marker: THY1     cell type: Adipo_MSC\n",
      "9 marker: THY1     cell type: THY1_MSC\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_10['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "id": "1acdf993-6bac-4ef3-89c7-f89e5cd4ee38",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: NCAM1     cell type: Endosteal\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_11['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "id": "134cd239-c585-49a4-8aaf-69f97728f7dd",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: CD8A     cell type: CD8_T_Cell\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_12['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "id": "d5c547db-86d4-4657-8e0c-ee9aba9d862d",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: TFRC     cell type: Erythroblast\n",
      "2 marker: TFRC     cell type: Erythroid\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_13['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "id": "df33bdb3-a265-4198-8e1b-43f81d98111b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "exit = [x for x in cluster_14['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "id": "e26982c7-50b7-4056-b377-dee2909b574a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: CD8A     cell type: CD8_T_Cell\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_15['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "id": "c059e88a-cf75-4380-b8d7-b144dc2e70de",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "exit = [x for x in cluster_16['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "id": "92273563-4e0a-4f9f-8d37-ba7692cd3a37",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: CXCL12     cell type: Adipo_MSC\n",
      "2 marker: CXCL12     cell type: THY1_MSC\n",
      "3 marker: CXCL12     cell type: AEC\n",
      "4 marker: CXCL12     cell type: SEC\n",
      "5 marker: VCAM1     cell type: Macrophages\n",
      "6 marker: THY1     cell type: HSC\n",
      "7 marker: THY1     cell type: GMP\n",
      "8 marker: THY1     cell type: Adipo_MSC\n",
      "9 marker: THY1     cell type: THY1_MSC\n",
      "10 marker: ACTA2     cell type: VSMC\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_17['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "id": "c0aab5cf-45c7-4ddd-9230-875d30ada378",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: THBD     cell type: Mature_Myeloid\n",
      "2 marker: CD14     cell type: Monocytes\n",
      "3 marker: CD14     cell type: Non_Classical_Monocyte\n",
      "4 marker: MCAM     cell type: Adipocyte\n",
      "5 marker: VCAM1     cell type: Macrophages\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_18['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "id": "d38b2102-73dd-419f-968f-25cd6bc42fa8",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: MPO     cell type: Early_Myeloid_Progenitor\n",
      "2 marker: MPO     cell type: Intermediate_Myeloid\n",
      "3 marker: MPO     cell type: Mature_Myeloid\n",
      "4 marker: TFRC     cell type: Erythroblast\n",
      "5 marker: TFRC     cell type: Erythroid\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_19['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "id": "5a017f00-f88a-4ab9-be99-2b08281de6d1",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: HLA-DRA     cell type: Non_Classical_Monocyte\n",
      "2 marker: CD79A     cell type: Immature_B_Cell\n",
      "3 marker: CD79A     cell type: B_Cells\n",
      "4 marker: CD79A     cell type: Plasma_Cells\n",
      "5 marker: PAX5     cell type: Immature_B_Cell\n",
      "6 marker: PAX5     cell type: B_Cells\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_20['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "id": "4a1ab21a-26f6-4034-8e3c-0d14c7ad4b34",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: HLA-DRA     cell type: Non_Classical_Monocyte\n",
      "2 marker: CD163     cell type: Macrophages\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_21['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "id": "acbc4570-308c-4ca1-940e-368db77fcd12",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: NCAM1     cell type: Endosteal\n",
      "2 marker: SPINK2     cell type: SPINK2_HSPC\n",
      "3 marker: SPINK2     cell type: HSPC\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_22['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "id": "ce27aeed-1994-405b-a59f-fee4c57dad0f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: THBD     cell type: Mature_Myeloid\n",
      "2 marker: IL3RA     cell type: pDC\n",
      "3 marker: MCAM     cell type: Adipocyte\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_23['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "id": "6112a85d-2f52-41b4-92af-db26e56a9900",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: NCAM1     cell type: Endosteal\n",
      "2 marker: VCAM1     cell type: Macrophages\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_24['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "id": "c916e045-77a8-4010-99ec-e45cd3698d9f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: CD79A     cell type: Immature_B_Cell\n",
      "2 marker: CD79A     cell type: B_Cells\n",
      "3 marker: CD79A     cell type: Plasma_Cells\n",
      "4 marker: HLA-DRA     cell type: Non_Classical_Monocyte\n",
      "5 marker: PAX5     cell type: Immature_B_Cell\n",
      "6 marker: PAX5     cell type: B_Cells\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_25['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "id": "3e107166-5ddc-4e4c-9a75-5cb7545db0f1",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: THBD     cell type: Mature_Myeloid\n",
      "2 marker: IL3RA     cell type: pDC\n",
      "3 marker: MCAM     cell type: Adipocyte\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_26['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "id": "8f536068-58d4-49f0-a61c-daf00aa8158a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: ACTA2     cell type: VSMC\n",
      "2 marker: MCAM     cell type: Adipocyte\n",
      "3 marker: THY1     cell type: HSC\n",
      "4 marker: THY1     cell type: GMP\n",
      "5 marker: THY1     cell type: Adipo_MSC\n",
      "6 marker: THY1     cell type: THY1_MSC\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_27['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "id": "e7a4f167-e008-4343-8065-208da14c7f34",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: PAX5     cell type: Immature_B_Cell\n",
      "2 marker: PAX5     cell type: B_Cells\n",
      "3 marker: HLA-DRA     cell type: Non_Classical_Monocyte\n",
      "4 marker: CD79A     cell type: Immature_B_Cell\n",
      "5 marker: CD79A     cell type: B_Cells\n",
      "6 marker: CD79A     cell type: Plasma_Cells\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_28['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "id": "b8b401e9-11ba-4060-aed2-dceed45a3b44",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: CD14     cell type: Monocytes\n",
      "2 marker: CD14     cell type: Non_Classical_Monocyte\n",
      "3 marker: ITGAX     cell type: Non_Classical_Monocyte\n",
      "4 marker: HLA-DRA     cell type: Non_Classical_Monocyte\n",
      "5 marker: THBD     cell type: Mature_Myeloid\n",
      "6 marker: CD163     cell type: Macrophages\n",
      "7 marker: TFRC     cell type: Erythroblast\n",
      "8 marker: TFRC     cell type: Erythroid\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_29['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "id": "8ae5577a-bb2e-472d-8d0d-b4b7dbec8a73",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "exit = [x for x in cluster_30['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "id": "d692125c-ccf2-48a8-a39c-c2c197fcb4f8",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: IL3RA     cell type: pDC\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_31['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "id": "54b9ccde-bea1-4f5e-80cc-23fdd9a0ee64",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: PLP1     cell type: Schwann_Cell\n",
      "2 marker: NCAM1     cell type: Endosteal\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_32['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "id": "d35c1c6e-4702-4c0e-bc87-64b2c167a802",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 marker: TFRC     cell type: Erythroblast\n",
      "2 marker: TFRC     cell type: Erythroid\n"
     ]
    }
   ],
   "source": [
    "exit = [x for x in cluster_33['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "id": "9e01452c-6274-4211-bb7d-d486352ea2a6",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "exit = [x for x in cluster_34['gene'].tolist() if x in geneList ]\n",
    "marker_result(exit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44829859-e6bc-484b-b82f-7345c2cfaa93",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "karl",
   "language": "python",
   "name": "karl"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
